<?php

declare (strict_types=1);

namespace app\adminapi\validate;

use think\Validate;

class AdminValidate extends Validate
{
    protected $rule = [
        'username' => 'require|max:32|min:3',
        'nickname' => 'require|max:30|min:1',
        'password' => 'require|min:8|confirm',
        'old_password' => 'require',
        'code' => 'require',
    ];

    protected $message = [
        'username.require' => '请填写管理员账号',
        'password.require' => '请填写管理员密码',
        'password.min' => '管理员密码不能少于8位',
        'password.confirm'     => '两次输入的密码不一致',
        'old_password.require' => '请输入原密码',
        'code.require' => '请填写验证码',
    ];

    // login 验证场景定义
    public function sceneLogin(): AdminValidate
    {
        return $this->only(['username','password', 'code'])
            ->remove('password', 'confirm');
    }

    public function sceneAdd(): AdminValidate
    {
        return $this->only(['username','password', 'nickname'])
            ->remove('password', 'confirm');
    }

    public function sceneEdit(): AdminValidate
    {
        return $this->only(['username', 'nickname'])
            ->remove('password', 'confirm');
    }

    protected $scene = [
        'login' => ['username', 'password', 'code'],
        'add' => ['username', 'nickname', 'password'],
        'edit' => ['username', 'nickname'],
        'changePassword' => ['old_password', 'password'],
    ];
}